package W;

import java.io.IOException;

public class Example {
   /* public static void main(String[] args) {
        String s = "abcd";
        Integer x = new Integer(3);
      String s2 = s + 4;
        s2 = null;
        s = null;
        }*/

   /*public static void main(String[] args) {
       String name;
       String newName = "Nick";
       newName = "Jason";
       name = "Frieda";
       String newestName = name;
       name = null;
       // 关键点
   }*/

   /* public static void main(String[] args) {
        try {
            System.out.print(Integer.parseInt("forty"));
        } catch (RuntimeException e) {
            System.out.println("Runtime");
        }
    }*/
   /*void topGo() {
       try {
           middleGo();
       } catch (Exception e) {
           System.out.println("catch");
       }
   }

    void middleGo() throws Exception {
        go();
        System.out.println("late middle");
    }

    void go() throws Exception {
        throw new Exception();
    }

    public static void main(String[] args) {
        Example example = new Example();
        example.topGo();
    }
}
*/

    /*public static void main(String[] args) {
        try {
            throw new Exception();
        } catch (Exception e) {
            try {
                throw new Exception();
            } catch (Exception e2) {
                System.out.println("inner");
            }
            System.out.println("middle");
        }
        System.out.println("out");
        System.out.println("AAA");
    }


}*/
   /* public static void main(String[] args) {
        try {
            System.out.println(new Example().getInt("42"));
        } catch (NumberFormatException e) {
            System.out.println("NFExc");
        }
    }

    int getInt(String arg) throws NumberFormatException {
        return Integer.parseInt(arg);
    }
}

class Utils {
    int getInt(String arg) {
        return 42;
    }
}*/

    /*public static void main(String[] args) throws Exception {
        try {
            System.out.println(new Example().getInt("42"));
        } catch (NumberFormatException e) {
            System.out.println("NFExc");
        }
    }
    int getInt(String arg) throws Exception{
        return Integer.parseInt(arg);
    }
}

class Utils {
    int getInt(String arg) throws Exception {
        return 42;
    }
}*/
   /* public static void main(String[] args) throws Exception {// a
        new Example().topGo();
    }

    void topGo() throws Exception {// b
        middleGo();
    }

    void middleGo() throws Exception {// c
        go();
        System.out.println("late middle");
    }

    void go() throws Exception {// d
        throw new Exception();
    }
}*/

    /*public static void main(String[] args) {
        try {
            System.out.println(args[0]);
            System.out.println("I'm nomal");
            if (true)
                return;
        } catch (Exception ex) {
            System.out.println("I'm exception");
            if (true)
                return;
        } finally {
            System.out.println("I'm finally.");
        }

        System.out.println("Out of try.");
    }
}
*/
    /*public static void main(String[] args) throws IOException {
        if (args[1] == "hello") {
            throw new IOException();
        }
    }
}*/
    /*public static void main(String[] args) throws IOException {
        System.out.println("Before Try");
        try {
        } catch (java.io.IOException e) {
            System.out.println("Inside Catch");
        }
        System.out.println("At the End");
    }
}*/

    /*public static void main(String[] args) throws IOException {
        try {
            return;
        } finally{

            System.out.println("Finally");
        }
    }
}*/

   /* public static void main(String[] args) throws IOException {
        aMethod();
    }

    static void aMethod(){
        try {
            System.out.println("Try");
            return;
        } catch (Exception e) {
            System.out.println("Catch");
        }finally{
            System.out.println("Finally");
        }
    }
}
*/

   /* public static String output = "";
    public static void foo(int i) {
        try {
            if (i == 1) {
                throw new Exception();
            }
            output += "1";
        } catch (Exception e) {
            output += "2";
            return;
        } finally {
            output += "3";
        }
        output += "4";
    }

    public static void main(String[] args) throws IOException {
        foo(0);
        foo(1);
        System.out.println(output);
    }
}*/

   /* int x = 0;

    public Example(int inVal) throws Exception {
        if (inVal != this.x) {
            throw new Exception("Invalid input");
        }
    }

    public static void main(String[] args) throws Exception {
        Example t = new Example(4);
    }
}*/

    /*public static void main(String[] args) {
        try {
            int x=Integer.parseInt("42a");
            //插入代码处
        } catch (IllegalArgumentException e) {
            System.out.println("oops");
        }
    }
}*/

    public static void main(String[] args) throws IOException {
        int i = 1, j = 1;
        try {
            i++;
            j--;
            if (i/j > 1) {
                j++;
            }
        } catch (ArithmeticException e) {
            System.out.println(0);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println(1);
        } catch (Exception e) {
            System.out.println(2);
        } finally {
            System.out.println(3);
        }
        System.out.println(4);
    }
}
